﻿using DefCore.Mapping;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DefCore.Structures
{
    public static class FrameManager
    {
        private static readonly int WALL_FRAME_X = 28;
        private static readonly int WALL_FRAME_Y = 128;
        
        public static Rectangle GetFrame(StructureFrameEnum frame, CellBase cell)
        {
            switch(frame)
            {
                case StructureFrameEnum.CENTERFRAME:                    
                    return new Rectangle(
                        (int)(cell.MapPosition.ScreenSpaceCoords.X + WALL_FRAME_X),
                        (int)(cell.MapPosition.ScreenSpaceCoords.Y + WALL_FRAME_X),
                        WALL_FRAME_Y, WALL_FRAME_Y);

                case StructureFrameEnum.NORTHFRAME:
                    return new Rectangle(
                        (int)(cell.MapPosition.ScreenSpaceCoords.X),
                        (int)(cell.MapPosition.ScreenSpaceCoords.Y),
                        (int)Globals.TileSize.X, WALL_FRAME_X);

                case StructureFrameEnum.SOUTHFRAME:
                     return new Rectangle(
                        (int)cell.MapPosition.ScreenSpaceCoords.X,
                        (int)(cell.MapPosition.ScreenSpaceCoords.Y + (Globals.TileSize.Y - WALL_FRAME_X)),
                        (int)Globals.TileSize.X, WALL_FRAME_X);

                case StructureFrameEnum.EASTFRAME:
                    return new Rectangle(
                        (int)(cell.MapPosition.ScreenSpaceCoords.X + (Globals.TileSize.X - WALL_FRAME_X)),
                        (int)cell.MapPosition.ScreenSpaceCoords.Y,
                        WALL_FRAME_X, (int)Globals.TileSize.Y);

                case StructureFrameEnum.WESTFRAME:
                     return new Rectangle(
                      (int)cell.MapPosition.ScreenSpaceCoords.X,
                      (int)cell.MapPosition.ScreenSpaceCoords.Y,
                      WALL_FRAME_X, (int)Globals.TileSize.Y);

                case StructureFrameEnum.FULLFRAME:
                     return new Rectangle(
                       (int)cell.MapPosition.ScreenSpaceCoords.X,
                       (int)cell.MapPosition.ScreenSpaceCoords.Y,
                       (int)Globals.TileSize.X, (int)Globals.TileSize.Y);

                case 0:
                default:
                     throw new Exception("ERROR: UNDEFINED AND UNEXPECTED ERROR");
            }

        }
    }
}
